home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS24.ADF / BNTools / LoadIt.ASM next >
Assembly Source File  |  1988-04-16  |  5KB  |  223 lines

  1. ;
  2. ; LoadIt (C)1987 Bryce Nesbitt.  Revokable, free, non-exclusive licence
  3. ; hereby granted to any sentient being to use or abuse this code in any way
  4. ; whatsoever provided that this and any other copyright notices remain fully
  5. ; attached, and with the exception that, without prior written permission,
  6. ; it not be utilized by any entity that has been commonly referred to as
  7. ; Robert W. Skyles, Skyles Electric Works, Jim Drew, Regie Warren or any
  8. ; organization founded by, controlled, employing or profiting any such
  9. ; entity, it's offspring or spouses.  FISH use ok.
  10. ;
  11. ; Author correspondence, bug or stupidity reports may be directed to:
  12. ; Bryce Nesbitt     ;bryce@cogsci.Berkeley.EDU
  13. ; 1712 Marin Ave.
  14. ; Berkeley, Ca 96034-9412
  15. ;
  16. ; USAGE:     LoadIt <file>
  17. ;
  18. ; FUNCTION:  Loads a file into memory, and reports the address.  The
  19. ;         file remains at that address until a re-boot.
  20. ;
  21. ; EXAMPLES:  LoadIt c:install
  22. ;         LoadIt Read Me    ;No parsing is done. Quotes not needed
  23. ;
  24. ; BUGS:      If there is an error during the read the allocated memory will
  25. ;         not be returned.
  26. ;
  27. ; Proper size when assembled with the Metacompost assembler
  28. ; and BLINK'ed is 424 bytes
  29. ;
  30. ; RETURN CODE CONVENTION:
  31. ;
  32. ; FAIL    (20) - serious error, no DOS, memory etc.
  33. ; ERROR (10) - user caused error. (file not found, syntax)
  34. ; WARN    (5)  - technicality such as file not found on DELETE.
  35. ;
  36. **************************
  37.     NOLIST
  38.     INCLUDE 'libraries/dosextens.i'
  39.     ;INCLUDE 'lib/exec_lib.i'        ;eliminates link with amiga.lib
  40.     ;INCLUDE 'lib/dos_lib.i'         ;non-standard, but very speedy!
  41.     LIST
  42. jsrlib    macro
  43.     xref    _LVO\1
  44.     jsr    _LVO\1(a6)
  45.     endm
  46. blink    macro
  47.     bchg.b #1, $bfe001
  48.     endm
  49. **************************
  50.     CODE
  51. ;
  52. reserved1    equr a7
  53. reserved2    equr a6
  54. lock        equr a5
  55. handle        equr a4
  56. block        equr a3
  57. reserved3    equr a2
  58.  
  59. returncode    equr d7
  60. resultcode    equr d6
  61. size        equr d5
  62. inline        equr d4
  63. reserved4    equr d3
  64. reserved5    equr d2
  65.  
  66. ;-- "parse" the string --
  67.         clr.b    -1(a0,d0)    ;null terminate string
  68.         move.l    a0,inline    ;the quick and dirty way.
  69. ;-- Set defaults --
  70.         suba.l    lock,lock
  71.         suba.l    handle,handle
  72.         moveq    #10,returncode    ;default ERROR code
  73. ;-- Open DOS --
  74.         move.l    4,a6
  75.         lea    DOSName(pc),a1
  76.         jsrlib    OldOpenLibrary    ;1.0 compatible
  77.         move.l    d0,a6        ;Look Ma, no error check!
  78. ;-- Get a lock --
  79.         move.l    inline,d1
  80.         moveq    #ACCESS_READ,d2
  81.         jsrlib    Lock
  82.         move.l    d0,d1
  83.         move.l    d0,lock
  84.         beq.s    e_lock
  85. ;-- Examine locked object [d1-lock] --
  86.         suba.l    #fib_SIZEOF,a7
  87.         move.l    a7,d2
  88.         ;[lock in d1]
  89.         jsrlib    Examine
  90.         tst.l    d0    ;grrr
  91.         beq.s    e_examine
  92.         move.l    fib_Size(a7),d0
  93.         adda.l    #fib_SIZEOF,a7
  94.         move.l    d0,size
  95.         beq    e_nosize
  96. ;-- Get enough memory to fit [d0-size] --
  97.         move.l    a6,-(a7)
  98.         ;[size in d0]
  99.         moveq    #0,d1    ;Any type of memory
  100.         move.l    4,a6
  101.         jsrlib    AllocMem
  102.         move.l    (a7)+,a6
  103.         move.l    d0,block
  104.         tst.l    d0    ;grrr
  105.         beq.s    e_memory
  106. ;-- Open object --
  107.         move.l    inline,d1
  108.         move.l    #MODE_OLDFILE,d2
  109.         jsrlib    Open
  110.         move.l    d0,handle
  111.         move.l    d0,d1
  112.         beq.s    e_open
  113. ;-- Read entire thing --
  114.         ;[handle in d1]
  115.         move.l    block,d2
  116.         move.l    size,d3
  117.         jsrlib    Read
  118.         cmp.l    d0,d3
  119.         bne.s    e_read
  120. ;-- Play leapfrog with deallocation --
  121.         moveq    #0,returncode    ;OK
  122. e_read
  123. e_open
  124. e_examine
  125. e_lock
  126. e_stuff     jsrlib    IoErr
  127.         move.l    d0,resultcode
  128. errorentry    move.l    handle,d1
  129.         beq.s    noclose
  130.         jsrlib    Close
  131. noclose     move.l    lock,d1
  132.         beq.s    nounlock
  133.         jsrlib    UnLock
  134. nounlock    tst.l    returncode
  135.         beq.s    noerrors
  136. ;-- print error --
  137.         lea    nocans(pc),a2
  138.         moveq    #nocane-nocans,d3
  139.         bsr.s    DOWRITE      ;error handling?
  140.         bra.s    closeup
  141. ;-- print stats --
  142. noerrors    lea    itsats(pc),a2
  143.         moveq    #itsate-itsats,d3
  144.         bsr.s    DOWRITE      ;error handling?
  145.         move.l    block,d0
  146.         moveq    #',',d3
  147.         bsr.s    PRINTLONGHEX ;error handling?
  148.         lea    sizes(pc),a2
  149.         moveq    #sizee-sizes,d3
  150.         bsr.s    DOWRITE      ;error handling?
  151.         move.l    size,d0
  152.         moveq    #10,d3
  153.         bsr.s    PRINTLONGHEX ;error handling?
  154. ;-- Close up --
  155. closeup     move.l    a6,a1    ;a6 had DosBase
  156.         move.l    4,a6
  157.         jsrlib    CloseLibrary
  158.         suba.l    a1,a1    ;zero out a1
  159.         jsrlib    FindTask    ;Find THIS task
  160.         move.l    d0,a0
  161.         move.l    resultcode,pr_Result2(a0) ;set WHY (or RESULT) code
  162.         move.l    returncode,d0
  163.         rts
  164. ;-- Handle out of memory --
  165. e_memory    moveq    #20,returncode    ;upgrade to FAIL
  166.         moveq    #ERROR_NO_FREE_STORE,resultcode
  167.         bra.s    errorentry
  168. ;-- Set misleading error message for zero byte length file --
  169. e_nosize    moveq    #ERROR_FILE_NOT_OBJECT,resultcode
  170.         bra.s    errorentry
  171. ;
  172. ;error=DOWRITE(buffer,length),dos
  173. ; z           a2     d3<>0
  174. ;
  175. DOWRITE     jsrlib    Output
  176.         move.l    d0,d1
  177.         beq.s    e_noout
  178.         move.l    a2,d2
  179.         ;[length in d3]
  180.         jsrlib    Write
  181. e_noout     ;cmp.l     d0,d3     ;check for mismatch
  182.         rts
  183. ;
  184. ;PRINTLONGHEX(value,terminator),dos
  185. ;          d0    d3.b
  186. ;
  187. PRINTLONGHEX    ;movem.l d0-d3/a0-a1,-(a7)
  188.         subq.l    #5,a7    ;Take 10 bytes from stack
  189.         subq.l    #5,a7    ;(it's smaller...)
  190.         move.l    a7,a0
  191.         moveq    #7,d2
  192.  
  193. 1$        rol.l    #4,d0
  194.         move.l    d0,d1
  195.         andi.w    #$f,d1
  196.         move.b    hextab2(pc,d1.w),(a0)+
  197.         dbra    d2,1$
  198.  
  199.         move.b    d3,(a0)
  200.         jsrlib    Output
  201.         move.l    d0,d1
  202.         beq.s    er_output
  203.         move.l    a7,d2
  204.         moveq    #9,d3
  205.         jsrlib    Write
  206.         addq.l    #5,a7
  207.         addq.l    #5,a7
  208. er_output
  209. er_lib        ;movem.l (a7)+,d0-d3/a0-a1
  210.         rts
  211.  
  212. DOSName     dc.b 'dos.library',0
  213. nocans        dc.b 'Can',39,'t load file',10
  214. nocane
  215. itsats        dc.b 'File loaded at address $'
  216. itsate
  217. sizes        dc.b ' size $'
  218. sizee
  219. hextab2     dc.b '0123456789ABCDEF'
  220.         dc.b '(C)1987 Bryce Nesbitt'
  221.         dc.b 1         ;release 1
  222. ;-- That's all folks --
  223.